package com.qisimanxiang.dalaran.zuul.config.converter;

import com.qisimanxiang.dalaran.zuul.util.JsonMapper;
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wangmeng
 * @date created in 10:32 上午 2019/9/16
 * @modified by
 */
@Component
@ConfigurationPropertiesBinding
public class StringToMapConverter implements Converter<String, Map<String, Integer>> {
    @Override
    public Map<String, Integer> convert(String s) {
        if (s == null) {
            return new HashMap<>(8);
        }
        return JsonMapper.NON_NULL.prase(s, HashMap.class);
    }
}
